{% set pypi_name = 'heat-agents' %}
{% set upstream_version = upstream_version('2.1.1') %}
{% set rpm_release = '1' %}
{% set source = url_pypi() %}

Name:           {{ py2name(py_versions='py3') }}
Version:        {{ py2rpmversion() }}
Release:        {{ py2rpmrelease() }}
Summary:        OpenStack Heat agents
License:        {{ license('Apache-2.0') }}
Group:          Development/Languages/Python
URL:            https://docs.openstack.org/heat-agents
Source0:        {{ source }}
BuildRequires:  openstack-macros
BuildRequires:  {{ py3('os-apply-config') }}
BuildRequires:  {{ py3('os-refresh-config') }}
BuildRequires:  {{ py3('pbr') }}
BuildArch:      noarch

%description
Heat Agents are python hooks for deploying software configurations using heat.

%prep
%autosetup -p1 -n {{ pypi_name }}-{{ upstream_version }}
%py_req_cleanup

# Replace "env python" shebag to the correct python executable
# if we don't do that brp-mangle-shebangs will choke on CentOS 8
for python_script in $(grep "%{_bindir}/env python" . -rl)
do
    sed -i "s#%{_bindir}/env python.*#%{_bindir}/python3#g" $python_script
done

%build

%install
# Use os-apply-config to bootstrap /etc/os-collect-config.conf
# from heat boot data
install -p -D -m 755 heat-config/os-refresh-config/configure.d/20-os-apply-config %{buildroot}%{_libexecdir}/os-refresh-config/configure.d/20-os-apply-config
install -p -D -m 600 heat-config/os-apply-config/%{_sysconfdir}/os-collect-config.conf %{buildroot}%{_libexecdir}/os-apply-config/templates/%{_sysconfdir}/os-collect-config.conf

# utilities which can be run by deployment scripts
install -p -D -m 755 heat-config/bin/heat-config-notify %{buildroot}/%{_bindir}/heat-config-notify
install -p -D -m 755 heat-config/bin/heat-config-rebuild-deployed %{buildroot}/%{_bindir}/heat-config-rebuild-deployed

# os-refresh-config script to run heat deployment resources
install -p -D -m 600 heat-config/os-apply-config/%{_localstatedir}/run/heat-config/heat-config %{buildroot}%{_libexecdir}/os-apply-config/templates/run/heat-config/heat-config
install -p -D -m 755 heat-config/os-refresh-config/configure.d/55-heat-config %{buildroot}%{_libexecdir}/os-refresh-config/configure.d/55-heat-config

# hook to perform configuration with scripts
install -p -D -m 755 heat-config-script/install.d/hook-script.py %{buildroot}%{_libexecdir}/heat-config/hooks/script

# hook to perform configuration with puppet
install -p -D -m 755 heat-config-puppet/install.d/hook-puppet.py %{buildroot}%{_libexecdir}/heat-config/hooks/puppet

# hook to perform configuration with ansible
install -p -D -m 755 heat-config-ansible/install.d/hook-ansible.py %{buildroot}%{_libexecdir}/heat-config/hooks/ansible

# hook to perform configuration with os-apply-config
install -p -D -m 755 heat-config-apply-config/install.d/hook-apply-config.py %{buildroot}%{_libexecdir}/heat-config/hooks/apply-config

# hook to perform configuration with hiera
install -p -D -m 755 heat-config-hiera/install.d/hook-hiera.py %{buildroot}%{_libexecdir}/heat-config/hooks/hiera

# hook to perform configuration with json-file
install -p -D -m 755 heat-config-json-file/install.d/hook-json-file.py %{buildroot}%{_libexecdir}/heat-config/hooks/json-file

# hook to perform configuration with docker commands
install -p -D -m 755 heat-config-docker-cmd/os-refresh-config/configure.d/50-heat-config-docker-cmd %{buildroot}%{_libexecdir}/os-refresh-config/configure.d/50-heat-config-docker-cmd
install -p -D -m 755 heat-config-docker-cmd/install.d/hook-docker-cmd.py %{buildroot}%{_libexecdir}/heat-config/hooks/docker-cmd

%package -n python3-heat-agent
Summary:  Agent for performing Heat software deployments
Requires:       {{ py3('dib-utils') }}
Requires:       {{ py3('heat-cfntools') }}
Requires:       {{ py3('python-heatclient') }}
Requires:       {{ py3('os-apply-config') }}
Requires:       {{ py3('os-collect-config') }}
Requires:       {{ py3('os-refresh-config') }}
Requires:       {{ py3('requests') }}
Requires:       {{ py3('python-zaqarclient') }}

%description -n python3-heat-agent
Heat Agents are python hooks for deploying software configurations using heat.

This package installs and configures os-collect-config to allow Heat software
deployments to perform script based configuration tasks.

%package -n python3-heat-agent-puppet
Summary:  Agent for performing Puppet based Heat software deployments
Requires:       puppet
Requires:       python3-heat-agent

%description -n python3-heat-agent-puppet
Heat Agents are python hooks for deploying software configurations using heat.

This package installs and configures os-collect-config to allow Heat software
deployments to perform puppet based configuration tasks.

%package -n python3-heat-agent-ansible
Summary:  Agent for performing Ansible based Heat software deployments
Requires:       {{ py2pkg('ansible') }}
Requires:       python3-heat-agent

%description -n python3-heat-agent-ansible
Heat Agents are python hooks for deploying software configurations using heat.

This package installs and configures os-collect-config to allow Heat software
deployments to perform ansible based configuration tasks.

%package -n python3-heat-agent-apply-config
Summary:  Agent for performing os-apply-config based Heat software deployments
Requires:       python3-heat-agent
Requires:       {{ py3('os-apply-config') }}

%description -n python3-heat-agent-apply-config
Heat Agents are python hooks for deploying software configurations using heat.

This package installs and configures os-collect-config to allow Heat software
deployments to perform os-apply-config based configuration tasks.

%package -n python3-heat-agent-hiera
Summary:  Agent for performing hiera based Heat software deployments
Requires:       python3-heat-agent

%description -n python3-heat-agent-hiera
Heat Agents are python hooks for deploying software configurations using heat.

This package installs and configures os-collect-config to allow Heat software
deployments to perform hiera based configuration tasks.

%package -n python3-heat-agent-json-file
Summary:  Agent for performing json-file based Heat software deployments
Requires:       python3-heat-agent

%description -n python3-heat-agent-json-file
Heat Agents are python hooks for deploying software configurations using heat.

This package installs and configures os-collect-config to allow Heat software
deployments to perform json-file based configuration tasks.

%package -n python3-heat-agent-docker-cmd
Summary:  Agent for performing Docker based Heat software deployments
Requires:       python3-heat-agent

%description -n python3-heat-agent-docker-cmd
Heat Agents are python hooks for deploying software configurations using heat.

This package installs and configures os-collect-config to allow Heat software
deployments to perform docker based configuration tasks.

%files
%license LICENSE

%files -n python3-heat-agent
%license LICENSE
%dir %{_libexecdir}/os-refresh-config/configure.d/
%dir %{_libexecdir}/os-apply-config/templates/run/heat-config
%{_bindir}/heat-config-notify
%{_bindir}/heat-config-rebuild-deployed
%dir %{_libexecdir}/os-apply-config/templates/%{_sysconfdir}/
%dir %{_libexecdir}/os-apply-config/templates/run/
%{_libexecdir}/os-apply-config/templates/%{_sysconfdir}/os-collect-config.conf
%{_libexecdir}/os-apply-config/templates/run/heat-config/heat-config
%{_libexecdir}/os-refresh-config/configure.d/20-os-apply-config
%{_libexecdir}/os-refresh-config/configure.d/55-heat-config
%dir %{_libexecdir}/heat-config
%dir %{_libexecdir}/heat-config/hooks
%{_libexecdir}/heat-config/hooks/script

%files -n python3-heat-agent-puppet
%license LICENSE
%{_libexecdir}/heat-config/hooks/puppet

%files -n python3-heat-agent-ansible
%{_libexecdir}/heat-config/hooks/ansible

%files -n python3-heat-agent-apply-config
%{_libexecdir}/heat-config/hooks/apply-config

%files -n python3-heat-agent-hiera
%{_libexecdir}/heat-config/hooks/hiera

%files -n python3-heat-agent-json-file
%{_libexecdir}/heat-config/hooks/json-file

%files -n python3-heat-agent-docker-cmd
%{_libexecdir}/heat-config/hooks/docker-cmd
%{_libexecdir}/os-refresh-config/configure.d/50-heat-config-docker-cmd

%changelog
